<?php
/**
 * PhpStorm
 * User: zucheng
 * Date: 2019/4/12
 */

use Illuminate\Database\Seeder;

class MemberTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     * @return void
     */
    public function run()
    {
        \App\Models\Member::truncate();
        \App\Models\MemberRelation::truncate();
        \App\Models\Driver::truncate();
        \App\Models\Owner::truncate();
        $members = [
            [
                'phone'   => '18631181614',
                'role_id' => 20,
            ],
            [
                'phone'   => '18903418202',
                'role_id' => 10,
            ],
            [
                'phone'   => '15635148202',
                'role_id' => 10,
            ],
            [
                'phone'   => '18903418201',
                'role_id' => 10,
            ]
        ];

        foreach ($members as $member) {
            $role   = $member['role_id'];
            $member['uuid'] = \Faker\Provider\Uuid::uuid();
            $member = \App\Models\Member::create($member);
            if ($role == 10) {
                \App\Models\Driver::create([
                    'member_id' => $member->id,
                    'uuid'      => $member->uuid,
                ]);
            } else if ($role == 20) {
                \App\Models\Owner::create([
                    'member_id' => $member->id,
                    'uuid'      => $member->uuid,
                ]);

                // 添加发货人
                $sender = \App\Models\Member::create([
                    'phone'     => '156' . mt_rand(10000000, 99999999),
                    'uuid'      => \Faker\Provider\Uuid::uuid(),
                    'role_id'   => 0,
                ]);
                \App\Models\MemberRelation::create([
                    'parent_id' => $member->id,
                    'member_id' => $sender->id,
                    'role_id'   => 21,
                ]);

                // 添加收货人
                $reciver = \App\Models\Member::create([
                    'phone'     => '156' . mt_rand(10000000, 99999999),
                    'uuid'      => \Faker\Provider\Uuid::uuid(),
                    'role_id'   => 0,
                ]);
                \App\Models\MemberRelation::create([
                    'parent_id' => $member->id,
                    'member_id' => $reciver->id,
                    'role_id'   => 22,
                ]);
            }
        }
    }
}